package com.chainshop.expenditure.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chainshop.common.core.domain.pojo.ExpenseRecords;
import com.chainshop.expenditure.service.IExpenseRecordsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chainshop.common.annotation.Log;
import com.chainshop.common.core.controller.BaseController;
import com.chainshop.common.core.domain.AjaxResult;
import com.chainshop.common.enums.BusinessType;

import com.chainshop.common.utils.poi.ExcelUtil;
import com.chainshop.common.core.page.TableDataInfo;

/**
 * 支出列表Controller
 * 
 * @author hmy
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/money/records")
public class ExpenseRecordsController extends BaseController
{
    @Autowired
    private IExpenseRecordsService expenseRecordsService;

    /**
     * 查询支出列表列表
     */
    @PreAuthorize("@ss.hasPermi('money:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExpenseRecords expenseRecords)
    {
        startPage();
        List<ExpenseRecords> list = expenseRecordsService.selectExpenseRecordsList(expenseRecords);
        return getDataTable(list);
    }

    /**
     * 导出支出列表列表
     */
    @PreAuthorize("@ss.hasPermi('money:records:export')")
    @Log(title = "支出列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExpenseRecords expenseRecords)
    {
        List<ExpenseRecords> list = expenseRecordsService.selectExpenseRecordsList(expenseRecords);
        ExcelUtil<ExpenseRecords> util = new ExcelUtil<ExpenseRecords>(ExpenseRecords.class);
        util.exportExcel(response, list, "支出列表数据");
    }

    /**
     * 获取支出列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('money:records:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(expenseRecordsService.selectExpenseRecordsById(id));
    }

    /**
     * 新增支出列表
     */
    @PreAuthorize("@ss.hasPermi('money:records:add')")
    @Log(title = "支出列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExpenseRecords expenseRecords)
    {
        return toAjax(expenseRecordsService.insertExpenseRecords(expenseRecords));
    }

    /**
     * 修改支出列表
     */
    @PreAuthorize("@ss.hasPermi('money:records:edit')")
    @Log(title = "支出列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExpenseRecords expenseRecords)
    {
        return toAjax(expenseRecordsService.updateExpenseRecords(expenseRecords));
    }

    /**
     * 删除支出列表
     */
    @PreAuthorize("@ss.hasPermi('money:records:remove')")
    @Log(title = "支出列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(expenseRecordsService.deleteExpenseRecordsByIds(ids));
    }
}
